import Request from 'utils/request';

export default class AddressApi {
  static getGoodsAddressList(mode, code) {
    let fun;
    if (mode === 'province') {
      fun = this.getProvinceData;
    } else if (mode === 'city') {
      fun = this.getCityData;
    } else if (mode === 'area') {
      fun = this.getAreaData;
    } else if (mode === 'street') {
      fun = this.getStreetData;
    }

    return fun(code);
  }

  static getProvinceData() {
    const apiName = 'api/wehcatshop/provincesAll';

    return Request.post(apiName).then(res => {
      return res.data;
    });
  }

  static getCityData(code) {
    const apiName = 'api/wehcatshop/cityAll';

    return Request.post(apiName, {
      provinceCode: code
    }).then(res => {
      return res.data;
    });
  }

  static getAreaData(code) {
    const apiName = 'api/wehcatshop/areaAll';

    return Request.post(apiName, {
      cityCode: code
    }).then(res => {
      return res.data;
    });
  }

  static getStreetData(code){
    const apiName = 'api/wehcatshop/streetAll';

    return Request.post(apiName, {
      areaCode: code
    }).then(res => {
      return res.data;
    });
  }
}
